/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.manager.CompanyStatusManager;
/*     */ import com.newcrm.thread.LuceneThread;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class AddUpdateCompany extends AbstractAddUpdateCustomerDeal
/*     */ {
/*  24 */   private int id = 0;
/*  25 */   private String indexPath = null;
/*     */ 
/*  27 */   private static Logger logger = Logger.getLogger(AddUpdateCompany.class
/*  28 */     .getName());
/*     */ 
/*     */   public AddUpdateCompany(AbstractHttpServlet servlet, String id, String indexPath)
/*     */   {
/*  32 */     super(servlet);
/*  33 */     this.id = Util.str2Int(id);
/*  34 */     this.indexPath = indexPath;
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException
/*     */   {
/*  42 */     if (!CompanyStatusManager.getInstance().getAddCompanyStatus()) {
/*  43 */       response.sendRedirect(request.getContextPath() + "/parties");
/*  44 */       return;
/*     */     }
/*     */ 
/*  47 */     User loginUser = super.getLoginUser(request);
/*  48 */     String userId = loginUser.userId;
/*  49 */     int companyId = loginUser.companyId;
/*     */ 
/*  51 */     String companyName = Util.getURLParameter(request
/*  52 */       .getParameter("companyName"));
/*  53 */     if ((companyName == null) || (companyName.trim().length() == 0)) {
/*  54 */       if (this.id <= 0)
/*  55 */         response.sendRedirect(request.getContextPath() + "/company/new");
/*     */       else {
/*  57 */         response.sendRedirect(request.getContextPath() + "/company/" + 
/*  58 */           this.id);
/*     */       }
/*  60 */       logger.warn("company name is null");
/*  61 */       return;
/*     */     }
/*  63 */     String companyNote = Util.getURLParameter(request
/*  64 */       .getParameter("background"));
/*     */ 
/*  66 */     int categoryId = Util.getURLIntParameter(request
/*  67 */       .getParameter("categoryId"));
/*     */ 
/*  69 */     List extInfos = new ArrayList();
/*     */ 
/*  71 */     addExtInfo(request, "phone", extInfos, 
/*  72 */       1);
/*     */ 
/*  74 */     addExtInfo(request, "email", extInfos, 
/*  75 */       2);
/*     */ 
/*  77 */     addExtInfo(request, "im", extInfos, 
/*  78 */       3);
/*     */ 
/*  80 */     addExtInfo(request, "website", extInfos, 
/*  81 */       4);
/*     */ 
/*  83 */     addExtInfo(request, "weibo", extInfos, 
/*  84 */       5);
/*     */ 
/*  86 */     addExtInfo(request, "address", extInfos, 
/*  87 */       6);
/*     */ 
/*  90 */     super.addFieldInfo(request, extInfos);
/*     */ 
/*  94 */     int visible = Util.getURLIntParameter(request.getParameter("visible"));
/*  95 */     String permissionsId = "";
/*     */ 
/*  97 */     String shareUserIds = "";
/*     */ 
/*  99 */     String shareGroupIds = "";
/*     */ 
/* 102 */     if (visible == 1)
/*     */     {
/* 104 */       permissionsId = Util.getURLParameter(request
/* 105 */         .getParameter("groupPermissionsId"));
/*     */     }
/* 107 */     else if (visible == 4)
/*     */     {
/* 109 */       permissionsId = Util.getURLParameter(request
/* 110 */         .getParameter("permissionsId"));
/*     */ 
/* 112 */       shareUserIds = StringUtils.join(
/* 113 */         request.getParameterValues("shareUserId"), ",");
/*     */ 
/* 115 */       shareGroupIds = StringUtils.join(
/* 116 */         request.getParameterValues("shareGroupId"), ",");
/*     */     }
/*     */ 
/* 120 */     CustomerManager manager = new CustomerManager();
/*     */ 
/* 122 */     if (this.id <= 0) {
/* 123 */       this.id = manager.addCompany(companyName, categoryId, companyNote, 
/* 124 */         visible, permissionsId, shareUserIds, shareGroupIds, null, 
/* 125 */         extInfos, userId, companyId);
/* 126 */       if (this.id < 0)
/*     */       {
/* 128 */         this.id *= -1;
/* 129 */         response.sendRedirect(request.getContextPath() + "/company/" + 
/* 130 */           this.id + "?duplicate=1");
/* 131 */         return;
/*     */       }
/*     */ 
/* 135 */       new LuceneThread(this.indexPath, false).start();
/*     */ 
/* 137 */       response.sendRedirect(request.getContextPath() + "/company/" + 
/* 138 */         this.id);
/* 139 */       return;
/*     */     }
/*     */ 
/* 143 */     int oldVisible = Util.getURLIntParameter(request
/* 144 */       .getParameter("oldVisible"));
/* 145 */     String oldPermissionsId = Util.getURLParameter(request
/* 146 */       .getParameter("oldPermissionsId"));
/* 147 */     String oldShareUserIds = Util.getURLParameter(request
/* 148 */       .getParameter("oldShareUserIds"));
/* 149 */     String oldShareGroupIds = Util.getURLParameter(request
/* 150 */       .getParameter("oldShareGroupIds"));
/*     */ 
/* 152 */     int hasModifyRight = Util.getURLIntParameter(request
/* 153 */       .getParameter("hasModifyRight"));
/* 154 */     if (hasModifyRight == 0)
/*     */     {
/* 156 */       visible = oldVisible;
/* 157 */       permissionsId = oldPermissionsId;
/* 158 */       shareUserIds = oldShareUserIds;
/* 159 */       shareGroupIds = oldShareGroupIds;
/*     */     }
/*     */ 
/* 162 */     String deleteExtInfoIds = request.getParameter("deleteExtInfoIds");
/* 163 */     manager.updateCompany(this.id, companyName, categoryId, companyNote, 
/* 164 */       hasModifyRight, visible, permissionsId, oldPermissionsId, 
/* 165 */       shareUserIds, oldShareUserIds, shareGroupIds, oldShareGroupIds, 
/* 166 */       null, false, extInfos, deleteExtInfoIds, userId, companyId);
/*     */ 
/* 169 */     new LuceneThread(this.indexPath, false).start();
/*     */ 
/* 171 */     response.sendRedirect(request.getContextPath() + "/company/" + this.id);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddUpdateCompany
 * JD-Core Version:    0.6.1
 */